<?php


namespace App\Models;


use Illuminate\Support\Facades\Hash;

class UserModel extends BaseModel
{
    const TABLE_NAME = 'user';

    const FIELD_USERNAME        = 'username';
    const FIELD_NICKNAME        = 'nickname';
    const FIELD_EMAIL           = 'email';
    const FIELD_PASSWORD        = 'password';
    const FIELD_PHONE           = 'phone';
    const FIELD_API_TOKEN       = 'api_token';
    const FIELD_REMEMBER_TOKEN  = 'remember_token';

    protected $fillable = [
        self::FIELD_USERNAME, self::FIELD_NICKNAME, self::FIELD_EMAIL, self::FIELD_PASSWORD, self::FIELD_PHONE,
        self::FIELD_API_TOKEN, self::FIELD_REMEMBER_TOKEN
    ];

    protected $hidden = [
        self::FIELD_PASSWORD, self::FIELD_REMEMBER_TOKEN
    ];


    public function setPasswordAttribute($value)
    {
        $this->attributes['password'] = Hash::make($value);
    }
}
